package de.g18.it0a.jlaser.domain;

import java.awt.geom.Line2D;


public class Line {

    private final Position firstPosition;
    private final Position secondPosition;


    public Line(Position aFirstPosition, Position aSecondPosition) {
        firstPosition = aFirstPosition;
        secondPosition = aSecondPosition;
    }

    public Line2D getLine2D() {
        return new Line2D.Double(getFirstPosition().getPoint(), getSecondPosition().getPoint());
    }

    public double getLength() {
        return Math.sqrt(Math.pow(getFirstPosition().getX() - getSecondPosition().getX(), 2)
                       + Math.pow(getFirstPosition().getY() - getSecondPosition().getY(), 2));
    }

    public Position getFirstPosition() {
        return firstPosition;
    }

    public Position getSecondPosition() {
        return secondPosition;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (firstPosition == null ? 0 : firstPosition.hashCode());
        result = prime * result + (secondPosition == null ? 0 : secondPosition.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object aObject) {
        if (this == aObject) {
            return true;
        }
        if (aObject == null) {
            return false;
        }
        if (!(aObject instanceof Line)) {
            return false;
        }

        Line other = (Line) aObject;
        return getFirstPosition().equals(other.getFirstPosition())
                && getSecondPosition().equals(other.getSecondPosition())
                || getFirstPosition().equals(other.getSecondPosition())
                && getSecondPosition().equals(other.getFirstPosition());
    }
}
